home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / terms / tipx / libacu / v3451.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-11  |  3.9 KB  |  195 lines

  1. /*
  2.  * Copyright (c) 1983 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that the above copyright notice and this paragraph are
  7.  * duplicated in all such forms and that any documentation,
  8.  * advertising materials, and other materials related to such
  9.  * distribution and use acknowledge that the software was developed
  10.  * by the University of California, Berkeley.  The name of the
  11.  * University may not be used to endorse or promote products derived
  12.  * from this software without specific prior written permission.
  13.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  14.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  15.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  16.  */
  17.  
  18. #ifndef lint
  19. static char sccsid[] = "@(#)v3451.c    5.2 (Berkeley) 9/13/88";
  20. #endif /* not lint */
  21.  
  22. /*
  23.  * Routines for calling up on a Vadic 3451 Modem
  24.  */
  25. #include "tip.h"
  26.  
  27. static    jmp_buf Sjbuf;
  28.  
  29. v3451_dialer(num, acu)
  30.     register char *num;
  31.     char *acu;
  32. {
  33.     int ok;
  34.     sigfunc_t (*func)();
  35.     int slow = number(value(BAUDRATE)) < 1200, rw = 2;
  36.     char phone[50];
  37. #ifdef ACULOG
  38.     char line[80];
  39. #endif
  40.  
  41.     /*
  42.      * Get in synch
  43.      */
  44.     vawrite("I\r", 1 + slow);
  45.     vawrite("I\r", 1 + slow);
  46.     vawrite("I\r", 1 + slow);
  47.     vawrite("\005\r", 2 + slow);
  48.     if (!expect("READY")) {
  49.         printf("can't synchronize with vadic 3451\n");
  50. #ifdef ACULOG
  51.         logent(value(HOST), num, "vadic", "can't synch up");
  52. #endif
  53.         return (0);
  54.     }
  55.     ioctl(FD, TIOCHPCL, 0);
  56.     sleep(1);
  57.     vawrite("D\r", 2 + slow);
  58.     if (!expect("NUMBER?")) {
  59.         printf("Vadic will not accept dial command\n");
  60. #ifdef ACULOG
  61.         logent(value(HOST), num, "vadic", "will not accept dial");
  62. #endif
  63.         return (0);
  64.     }
  65.     strcpy(phone, num);
  66.     strcat(phone, "\r");
  67.     vawrite(phone, 1 + slow);
  68.     if (!expect(phone)) {
  69.         printf("Vadic will not accept phone number\n");
  70. #ifdef ACULOG
  71.         logent(value(HOST), num, "vadic", "will not accept number");
  72. #endif
  73.         return (0);
  74.     }
  75.     func = signal(SIGINT,SIG_IGN);
  76.     /*
  77.      * You cannot interrupt the Vadic when its dialing;
  78.      * even dropping DTR does not work (definitely a
  79.      * brain damaged design).
  80.      */
  81.     vawrite("\r", 1 + slow);
  82.     vawrite("\r", 1 + slow);
  83.     if (!expect("DIALING:")) {
  84.         printf("Vadic failed to dial\n");
  85. #ifdef ACULOG
  86.         logent(value(HOST), num, "vadic", "failed to dial");
  87. #endif
  88.         return (0);
  89.     }
  90.     if (boolean(value(VERBOSE)))
  91.         printf("\ndialing...");
  92.     ok = expect("ON LINE");
  93.     signal(SIGINT, func);
  94.     if (!ok) {
  95.         printf("call failed\n");
  96. #ifdef ACULOG
  97.         logent(value(HOST), num, "vadic", "call failed");
  98. #endif
  99.         return (0);
  100.     }
  101.     ioctl(FD, TIOCFLUSH, &rw);
  102.     return (1);
  103. }
  104.  
  105. v3451_disconnect()
  106. {
  107.  
  108.     close(FD);
  109. }
  110.  
  111. v3451_abort()
  112. {
  113.  
  114.     close(FD);
  115. }
  116.  
  117. static
  118. vawrite(cp, delay)
  119.     register char *cp;
  120.     int delay;
  121. {
  122.  
  123.     for (; *cp; sleep(delay), cp++)
  124.         write(FD, cp, 1);
  125. }
  126.  
  127. static
  128. expect(cp)
  129.     register char *cp;
  130. {
  131.     char buf[300];
  132.     register char *rp = buf;
  133.     int alarmtr(), timeout = 30, online = 0;
  134.  
  135.     if (strcmp(cp, "\"\"") == 0)
  136.         return (1);
  137.     *rp = 0;
  138.     /*
  139.      * If we are waiting for the Vadic to complete
  140.      * dialing and get a connection, allow more time
  141.      * Unfortunately, the Vadic times out 24 seconds after
  142.      * the last digit is dialed
  143.      */
  144.     online = strcmp(cp, "ON LINE") == 0;
  145.     if (online)
  146.         timeout = number(value(DIALTIMEOUT));
  147.     signal(SIGALRM, alarmtr);
  148.     if (setjmp(Sjbuf))
  149.         return (0);
  150.     alarm(timeout);
  151.     while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) {
  152.         if (online && notin("FAILED CALL", buf) == 0)
  153.             return (0);
  154.         if (read(FD, rp, 1) < 0) {
  155.             alarm(0);
  156.             return (0);
  157.         }
  158.         if (*rp &= 0177)
  159.             rp++;
  160.         *rp = '\0';
  161.     }
  162.     alarm(0);
  163.     return (1);
  164. }
  165.  
  166. static
  167. alarmtr()
  168. {
  169.  
  170.     longjmp(Sjbuf, 1);
  171. }
  172.  
  173. static
  174. notin(sh, lg)
  175.     char *sh, *lg;
  176. {
  177.  
  178.     for (; *lg; lg++)
  179.         if (prefix(sh, lg))
  180.             return (0);
  181.     return (1);
  182. }
  183.  
  184. static
  185. prefix(s1, s2)
  186.     register char *s1, *s2;
  187. {
  188.     register char c;
  189.  
  190.     while ((c = *s1++) == *s2++)
  191.         if (c == '\0')
  192.             return (1);
  193.     return (c == '\0');
  194. }
  195.